﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace The_Last_Knights.GUI
{
    public class Groupbox: Element2D
    {
        #region Attributes
        protected Dictionary<string, Element2D> _elements;
#endregion

        #region Properties
        public Dictionary<string, Element2D> Elements
        {
            get { return _elements; }
            set { _elements = value; }
        }
#endregion

        public Groupbox(Game game, string ID, Vector2 pos, Vector2 size, Texture2D background) 
            : base(game, ID, pos, size, background)
        {
            _elements = new Dictionary<string, Element2D>();
        }

        public virtual bool AddElement(string id, Element2D obj)
        {
            if (_elements.ContainsKey(id))
                return false;
            _elements.Add(id, obj);
            return true;
        }

        public virtual bool RemoveElement(string id)
        {
            if (_elements.ContainsKey(id))
            {
                _elements.Remove(id);
                return true;
            }
            return false;
        }

        public virtual Element2D GetElement(string id)
        {
            return _elements.ContainsKey(id) ? _elements[id] : null;
        }

        public override void Update(GameTime gameTime)
        {
            foreach (var element2D in _elements)
            {
                element2D.Value.Update(gameTime);
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            foreach (var element2D in _elements)
            {
                element2D.Value.Draw(gameTime);
            }
        }
    }
}
